<?PHP
session_start();
include("../config/connect.php");
include("../public/common.php");

if( !isset($_SESSION["gs_user"]) ) 
{
	$url = "Location:login.php";
	header($url);
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>购物兔</title>
<style type="text/css">
<!--
body,td,th {
	font-family: 宋体;
	font-size: 13px;
	color: #000;
}
body {
	background-color: #FFF;
}
-->
</style>
<script language="javascript">
function OnFind()
{
	var input_item = document.getElementById("input_item").value;
 	var input_tradeid = document.getElementById("input_tradeid").value;
	var input_tbid = document.getElementById("input_tbid").value;
	window.location.href= "find_item.php?input_item=" + input_item + "&input_tradeid=" + input_tradeid + "&input_tbid=" + input_tbid;
}
</script>
</head>

<body>


<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td colspan="9" height="22"><a href="view_discount.php">自动返现</a></td>
    </tr>
	<tr>
    	<td height="25" width="50" align="center">序列号</td>
        <td width="200" align="center">时间</td>
      	<td width="198" align="center">产品Id</td>
        <td width="70" 	align="center">返现(元)</td>
        <td width="144" align="center">交易流水号</td>
        <td width="158" align="center">支付宝帐号</td>
        <td width="113" align="center">ip</td>
        <td width="60" align="center">转换</td>
        <td width="143" align="center">操作</td>
    </tr>
<?php
$input_item = trim(CheckUrlParamNoDie( "input_item" ));
$input_tbid = trim(CheckUrlParamNoDie( "input_tbid" ));
$input_tradeid = trim(CheckUrlParamNoDie( "input_tradeid" ));
$input_tradeid_sql = substr($input_tradeid, 0, 7);
$opt = trim(CheckUrlParamNoDie( "opt" ));
$id = SetUrlParamInt("id");
$find_flag = $input_item != "" || $input_tradeid != "" || $input_tbid != "";

if( $input_item != "" )
{
	$sql = "select * from trade where item_id='$input_item' order by id desc";
	$result = mysql_query( $sql );
}
else if( $input_tradeid != "" )
{
	$sql = "select * from trade where trade_id like '$input_tradeid_sql%' order by id desc";
	$result = mysql_query( $sql );
}
else if( $input_tbid != "" )
{
	$sql = "select * from trade where tb_id = '$input_tbid' order by id desc";
	$result = mysql_query( $sql );
}


// 默认浏览器
if( $opt == "ie_hide" )
{
	$sql = "update other_trade set state=1 where id=$id limit 1";
	mysql_query( $sql );
	echo "<script>window.history.back()</script>";
	exit;
}
if( $opt == "ie_del" )
{
	$sql = "delete from other_trade where id=$id";
	mysql_query( $sql );
	echo "<script>window.history.back()</script>";
	exit;
}

// 手工申请的
if ($opt == "manul_del")
{
	$sql = "delete from feedback where id=$id";
	mysql_query( $sql );
	echo "<script>alert(\"删除成功！\");window.history.back()</script>";
	exit;
}

//
if( $id != 0 && $opt == "returnall" )
{
	$sql = "update trade set has_return=1 where id=$id limit 1";
	mysql_query( $sql );
	//header("Location:view_discount.php?showtype=".$showtype);
	echo "<script>window.history.back()</script>";
	exit;
}

//部分返现
if( $id != 0 && $opt == "returnpart" )
{
	$sql = "update trade set has_return=2 where id=$id limit 1";
	mysql_query( $sql );
	//header("Location:view_discount.php?showtype=".$showtype);
}

while( $find_flag && $row = mysql_fetch_assoc( $result ) )
{
	if( $row["use_discount"] == "1" )
		$use_discount = "<strong><span style=\"color:#F00\">是</span></strong>";
	else
		$use_discount = "否";
?>
<tr title="<?PHP echo $row["info"]; ?>" bgcolor="<?PHP if ($row["has_return"] == 1) echo "#33CCFF"; else if ($row["has_return"] == 2) echo "#CC6666"; ?>">
    <td height="25" width="50" align="center"><?PHP echo $row["id"]; ?></td>
    <td width="200" align="center" title=""><?PHP echo $row["time"]; ?></td>
	<td width="198" align="center"><?PHP echo $row["item_id"]; ?>&nbsp;</td>
	<td width="70" 	align="center"><?PHP echo $row["discount"]; ?>&nbsp;</td>
	<td width="144" align="center"><a href="view_trade.php?trade=<?PHP echo $row["trade_id"]; ?>"><?PHP echo $row["trade_id"]; ?></a>&nbsp;</td>
	<td width="158" align="center"><a href="view_user.php?all=1&tb_id=<?PHP echo $row["tb_id"]; ?>"><?PHP echo $row["tb_id"]; ?></a>&nbsp;</td>
    <td width="113" align="center"><?PHP echo $row["ip"]; ?>&nbsp;</td>
    <td width="60" align="center"><?PHP echo $use_discount; ?>&nbsp;</td>
	<td width="143" align="center">
    	<a href="find_item.php?opt=returnall&input_item=<?PHP echo $input_item; ?>&id=<?PHP echo $row["id"]; ?>">全部返现</a>&nbsp;&nbsp;
        <a href="find_item.php?opt=returnpart&input_item=<?PHP echo $input_item; ?>&id=<?PHP echo $row["id"]; ?>">部分返现</a></td>
</tr>
<?PHP
}
?>
</table>
<br /><br />

<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td colspan="9" height="22"><a href="view_other_trade.php">通过默认浏览器购物</a></td>
    </tr>
	<tr>
    	<td height="25" width="45" align="center">序列号</td>
      <td width="124" align="center">时间</td>
   	  <td width="151" align="center">产品Id</td>
      <td width="60" 	align="center">返现(元)</td>
      <td width="50" align="center">返现(%)</td>
      <td width="160" align="center">支付宝帐号</td>
      <td width="59" align="center">ip</td>
      <td width="208" align="center">标题</td>
      <td width="106" align="center">操作</td>
  </tr>
<?php

if( $input_item != "" )
{
	$sql = "select * from other_trade where item_id='$input_item'order by id desc";
	$result = mysql_query( $sql );
}
else if( $input_tbid != "" )
{
	$sql = "select * from other_trade where tb_id = '$input_tbid' order by id desc";
	$result = mysql_query( $sql );
}

while( $find_flag && $row = mysql_fetch_assoc( $result ))
{
?>
<tr title="<?PHP echo $row["title"]; ?>" <?PHP if ($row["state"] == 1) echo "bgcolor=\"#33CCFF\""; ?>>
    <td height="25" width="45" align="center"><?PHP echo $row["id"]; ?></td>
    <td width="124" align="center" title=""><?PHP echo $row["time"]; ?></td>
	<td width="151" align="center"><a href="add_trade.php?id=<?PHP echo $row["id"]; ?>&item_id=<?PHP echo $row["item_id"]; ?>"><?PHP echo $row["item_id"]; ?></a>&nbsp;</td>
	<td width="60" 	align="center"><?PHP echo $row["price"]; ?>&nbsp;</td>
	<td width="50" align="center"><?PHP echo $row["percent"]; ?>&nbsp;</td>
	<td width="160" align="center"><a href="view_user.php?all=1&tb_id=<?PHP echo $row["tb_id"]; ?>"><?PHP echo $row["tb_id"]; ?></a>&nbsp;</td>
    <td width="59" align="center"><?PHP echo $row["ip"]; ?>&nbsp;</td>
    <td width="208" align="center"><?PHP echo $row["title"]; ?>&nbsp;</td>
	<td width="106" align="center">
    	<a href="find_item.php?opt=ie_hide&input_item=<?PHP echo $input_item; ?>&id=<?PHP echo $row["id"]; ?>">标志已处理</a>
        <a href="find_item.php?opt=ie_del&input_item=<?PHP echo $input_item; ?>&id=<?PHP echo $row["id"]; ?>">删除</a>   	</td>
</tr>
<?PHP
}
?>
</table>
<br />
<br />

<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td colspan="11" height="22"><a href="record_list.php">已返现的</a></td>
    </tr>
	<tr>
    	<td height="25" width="50" align="center">序列号</td>
        <td width="118" align="center">时间</td>
      	<td width="300" align="center">产品Id</td>
        <td width="68" 	align="center">共返现</td>
        <td width="76" align="center">成交额</td>
        <td width="76" align="center">已返现</td>
        <td width="166" align="center">支付宝帐号</td>
        <td width="100" align="center">订单号</td>
        <td width="87" align="center">手机</td>
        <td width="78" align="center">全部返回</td>
		<td width="50" align="center">对应</td>
    </tr>
<?php
$tb_opt = CheckUrlParamNoDie("tb_opt");
if( $tb_opt == "1" )
{
	$id = SetUrlParamInt( "id" );
	$sql = "update return_record set state=1 where id=$id";
	mysql_query( $sql );
	echo "<script>window.history.back()</script>";
	exit;
}

if( $input_item != "" )
{
	$item = "%".$input_item."%";
	$sql = "select * from return_record where item_id like '$item' order by id desc";	
	$result = mysql_query( $sql );
}
else if( $input_tradeid != "" )
{
	$sql = "select * from return_record where trade_id like '$input_tradeid_sql%' order by id desc";
	$result = mysql_query( $sql );
}
else if( $input_tbid != "" )
{
	$sql = "select * from return_record where tb_id = '$input_tbid' order by id desc";
	$result = mysql_query( $sql );
}

while( $find_flag && $row = mysql_fetch_assoc( $result ))
{
?>
<tr <?PHP if( $row["state"] == 1 ) 
												echo "bgcolor=\"#33CCFF\"" ?> >
    <td height="25" width="50" align="center"><?PHP echo $row["id"]; ?></td>
    <td width="118" align="center" title=""><?PHP echo $row["time"]; ?></td>
	<td width="300" align="center" title="<?PHP echo $row["item_id"]; ?>" class="text_limit"><div class="text_limit"><?PHP echo $row["item_id"]; ?></div>&nbsp;</td>
	<td width="68" 	align="center"><?PHP echo $row["all_return"]; ?>&nbsp;</td>
    <td width="76" align="center"><?PHP echo $row["price"]; ?>&nbsp;</td>
	<td width="76" align="center"><?PHP echo $row["has_return"]; ?>&nbsp;</td>
	<td width="166" align="center"><a href="view_user.php?all=1&tb_id=<?PHP echo $row["tb_id"]; ?>"><?PHP echo $row["tb_id"]; ?></a>&nbsp;</td>
    <td width="100" align="center"><a href="view_trade.php?trade=<?PHP echo $row["trade_id"]; ?>&id=<?PHP echo $row["id"]; ?>"><?PHP echo $row["trade_id"]; ?></a>&nbsp;</td>
    <td width="87" align="center"><?PHP echo $row["phone"]; ?>&nbsp;</td>
	<td width="78" align="center"><?PHP echo $row["b_return"] == 1?"是":"否"; ?></td>
	<td width="78" align="center"><?PHP if( $row["state"] == 1 )
											echo "<strong><span style=\"color:#F00\">是</span></strong>";
										else 
											echo "<a href=\"find_item.php?id=".$row["id"]."&tb_opt=1&input_item=".$input_item."\">否</a>"; ?></td>
</tr>
<?PHP
}
?>
</table>

<br />
<br />

<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td colspan="11" height="22"><a href="view_feedback.php">手工申请的</a></td>
    </tr>
	<tr>
    	<td height="25" width="50" align="center">序列号</td>
        <td width="140" align="center">时间</td>
   	  <td width="443" align="center">产品url</td>
      <td width="68" 	align="center">返现价格</td>
        <td width="161" align="center">支付宝帐号</td>
		<td width="41" align="center">对应</td>
	  <td width="64" align="center">操作</td>
  </tr>
<?php

if( $tb_opt == "2" )
{
	$id = SetUrlParamInt( "id" );
	$sql = "update feedback set state=1 where id=$id";
	mysql_query( $sql );
	echo "<script>window.history.back()</script>";
	exit;
}

if( $input_item != "" )
{
	$item = "%".$input_item."%";
	$sql = "select * from feedback where item_url like '$item' order by id desc";	
	$result = mysql_query( $sql );
}
else if( $input_tradeid != "" )
{
	$sql = "select * from feedback where item_url like '$input_tradeid_sql%' or price like '$input_tradeid_sql%' order by id desc";
	$result = mysql_query( $sql );
}
else if( $input_tbid != "" )
{
	$sql = "select * from feedback where tb_id = '$input_tbid' order by id desc";
	$result = mysql_query( $sql );
}

while( $find_flag && $row = mysql_fetch_assoc( $result ))
{
?>
	<tr title="<?PHP echo $row["info"]; ?>" <?PHP if( $row["state"] == 1 ) 
													echo "bgcolor=\"#33CCFF\"" ?> >
		<td height="25" width="50" align="center"><?PHP echo $row["id"]; ?></td>
		<td width="140" align="center" title=""><?PHP echo $row["time"]; ?></td>
	  <td width="443" align="center" title="<?PHP echo $row["item_url"]; ?>" class="text_limit"><div class="text_limit"><?PHP echo $row["item_url"]; ?></div>&nbsp;</td>
	  <td width="68" align="center"><?PHP echo $row["price"]; ?>&nbsp;</td>
		<td width="161" align="center"><?PHP echo $row["tb_id"]; ?>&nbsp;</td>
		<td width="41" align="center"><?PHP if( $row["state"] == 1 )
												echo "<strong><span style=\"color:#F00\">是</span></strong>";
											else 
												echo "<a href=\"find_item.php?id=".$row["id"]."&tb_opt=2&input_item=".$input_item."\">否</a>"; ?></td>
	  <td width="64" align="center">
   	    <a href="add_trade.php?id=<?php echo $row["id"]; ?>&opt_add=1&trade_id=<?php echo $input_tradeid; ?>">添加</a>
      <a href="find_item.php?id=<?php echo $row["id"]; ?>&opt=manul_del">删除</a></td>
  </tr>
<?PHP
}
?>
</table>

<table cellpadding="0" cellspacing="10" border="0" align="center">
	<tr>
   	  <td width="800" height="30" align="center">
      商品ID<input type="text" value="<?PHP echo $input_item; ?>" id="input_item" size="20"/>	 	  
   	  &nbsp;&nbsp;订单号<input type="text" value="<?PHP echo $input_tradeid; ?>" id="input_tradeid" size="20"/>
      &nbsp;&nbsp;用户Id<input type="text" value="<?PHP echo $input_tbid; ?>" id="input_tbid" size="20"/>
      <br><br><input type="button" onclick="javascript:OnFind();" value="查找" style="width:300px;" /></td>
    </tr>
    <tr><td></td></tr>
    <tr><td><a href="add_trade.php?opt=add">添加记录</a></td></tr>
</table>
</body>
</html>
